package parser

import (
	"go-learning-process/crawler/engine"
	"regexp"
)

const (
	// <a href="http://album.zhenai.com/u/1195899308" target="_blank">唯一</a>
	//cityRe = `<a href="(http://album.zhenai.com/u/[0-9]+ )"[^>]*>([^<] )</a>`
	cityRe = `<a href="(http://album.zhenai.com/u/[0-9]+)" [^>]*>([^<]+)</a>`
)

func ParseCity(contents []byte) engine.ParseResult {
	re := regexp.MustCompile(cityRe)
	matches := re.FindAllSubmatch(contents, -1)
	//log.Printf("City %s", matches)
	result := engine.ParseResult{}

	for _, m := range matches {
		result.Items = append(result.Items, "User "+string(m[2]))
		result.Requests = append(result.Requests,
			engine.Request{
				//用户信息对应的URL,用于之后的用户信息爬取
				Url: string(m[1]),
				//这个parser是对城市下面的用户的parse
				ParserFunc: func(c []byte) engine.ParseResult {
					return ParseProfile(c, string(m[2]))
				},
			})
	}

	return result
}
